using System;
using System.Collections.Generic;
using System.Text;

using UMEVOR.DTO;
using UMEVOR.DAL;

namespace UMEVOR.BLL
{
    public class BLLT_HIST_ARTIGO
    {

        #region Métodos de Validação

        private bool validarIncluir(T_HIST_ARTIGO obj)
        {
            return true;
        }
        private bool validarAlterar(T_HIST_ARTIGO obj)
        {
            return true;
        }
        private bool validarExcluir(T_HIST_ARTIGO obj)
        {
            return true;
        }
        #endregion

        #region Métodos DML

        public bool incluir(T_HIST_ARTIGO obj)
        {
            try
            {
                if (validarIncluir(obj))
                {
                    DALConnection.beginTransaction();
                    DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                    dal.incluir(obj);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool incluir(T_HIST_ARTIGO[] objs)
        {
            try
            {
                bool bValidos = true;
                foreach (T_HIST_ARTIGO obj in objs)
                {
                    if (!validarIncluir(obj))
                    {
                        bValidos = false;
                        break;
                    }
                }
                if (bValidos)
                {
                    DALConnection.beginTransaction();
                    DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                    dal.incluir(objs);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool alterar(T_HIST_ARTIGO obj)
        {
            try
            {
                if (validarAlterar(obj))
                {
                    DALConnection.beginTransaction();
                    DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                    dal.alterar(obj);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool alterar(T_HIST_ARTIGO[] objs)
        {
            try
            {
                bool bValidos = true;
                foreach (T_HIST_ARTIGO obj in objs)
                {
                    if (!validarAlterar(obj))
                    {
                        bValidos = false;
                        break;
                    }
                }
                if (bValidos)
                {
                    DALConnection.beginTransaction();
                    DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                    dal.alterar(objs);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool excluir(T_HIST_ARTIGO obj)
        {
            try
            {
                if (validarExcluir(obj))
                {
                    DALConnection.beginTransaction();
                    DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                    dal.excluir(obj);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool excluir(T_HIST_ARTIGO[] objs)
        {
            try
            {
                bool bValidos = true;
                foreach (T_HIST_ARTIGO obj in objs)
                {
                    if (!validarExcluir(obj))
                    {
                        bValidos = false;
                        break;
                    }
                }
                if (bValidos)
                {
                    DALConnection.beginTransaction();
                    DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                    dal.excluir(objs);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public T_HIST_ARTIGO obterPorPK(long pID_ARTIGO, object pDT_ACESSO)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                T_HIST_ARTIGO obj = dal.obterPorPK(pID_ARTIGO, pDT_ACESSO);
                DALConnection.commitTransaction();
                return obj;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public List<T_HIST_ARTIGO> listarTodos()
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                List<T_HIST_ARTIGO> objs = dal.listarTodos();
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public List<VOT_HIST_ARTIGO> consultar(DateTime inicio, DateTime fim)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_HIST_ARTIGO dal = new DALT_HIST_ARTIGO();
                List<VOT_HIST_ARTIGO> objs = dal.consultar(inicio,fim);
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }
        #endregion

    }
}
